import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

/// 状态
enum ViewState { idle, busy, error, success }

/// 页面状态
class ViewModel extends ChangeNotifier {
  final CancelToken _cancelToken = CancelToken();

  ViewState _viewState = ViewState.idle;

  @mustCallSuper
  ViewModel() {
    debugPrint('$this init');
  }

  CancelToken get cancelToken => _cancelToken;

  ViewState get viewState => _viewState;

  set viewState(ViewState value) {
    debugPrint('$this $value');
    _viewState = value;
    notifyListeners();
  }

  @mustCallSuper
  @override
  void dispose() {
    debugPrint('$this dispose');
    _cancelToken.cancel('已取消');
    super.dispose();
  }
}
